﻿#include <iostream>
#include <string>
#include <deque>
#include <algorithm>

using namespace std;

class MinStack {
public:
	void push(int x) {
		if(values.empty()){
			mins.push_back(x);
			values.push_back(x);
		}
		else{
			if(x<=mins.back())
				mins.push_back(x);
			values.push_back(x);
		}
	}

	void pop() {
		if(values.back()==mins.back())
			mins.pop_back();
		values.pop_back();
	}

	int top() {
		return values.back();
	}

	int getMin() {
		return mins.back();
	}

	void toString(){
		cout<<"[";
		for(int i=0;i<values.size();++i)
		{
			cout<<values[i];
			if(i!=values.size()-1)
				cout<<",";
		}
		cout<<"]"<<endl;
	}

private:
	deque<int> values;
	deque<int> mins;
};

int main(){

	MinStack stack;
	//stack.push(3);
	//stack.toString();
	//cout<<"Top:"<<stack.top()<<endl;
	//cout<<"Min:"<<stack.getMin()<<endl;

	//stack.push(2);
	//stack.push(1);
	//stack.push(5);
	//stack.push(6);
	//stack.toString();
	//cout<<"Top:"<<stack.top()<<endl;
	//cout<<"Min:"<<stack.getMin()<<endl;

	//stack.pop();
	//stack.toString();
	//cout<<"Top:"<<stack.top()<<endl;
	//cout<<"Min:"<<stack.getMin()<<endl;

	//stack.push(2147483646);
	//stack.push(2147483646);
	//stack.push(2147483647);
	//stack.top();
	//stack.pop();
	//stack.getMin();
	//stack.pop();
	//stack.getMin();
	//stack.pop();
	//stack.push(2147483647);
	//stack.top();
	//stack.getMin();
	//stack.push(-2147483648);
	//stack.top();
	//stack.getMin();
	//stack.pop();
	//stack.getMin();

	stack.push(-2);
	stack.push(0);
	stack.push(-1);
	cout<<stack.getMin();
	cout<<stack.top();
	stack.pop();
	cout<<stack.getMin();
}